<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
        <title>订单列表</title>
        <link rel="stylesheet" href="<c:url value="/static/wx/css/style.css"/>" />
        <script type="text/javascript" src="<c:url value="/static/wx/js/lib/rem.js"/>"></script>
    </head>
    <body class="bf">
        <div id="wrap">
            <ul class="ul-tab-btn clearfix">
                <li class="on"><a onclick="serchOrderList('')">全部订单</a><i></i></li>
                <li><a onclick="serchOrderList(1)">进行中</a><i></i></li>
                <li><a onclick="serchOrderList(2)">已完成</a><i></i></li>
                <li><a onclick="serchOrderList(3)">已失效</a><i></i></li>
            </ul>
            
            <div class="order_noData tc" id="no_list"></div>
            <div class="order_list" id="order_list"></div>
            
            <!--订单取消确定提示提示弹窗开始-->
            <div class="mask">
                <div class="toolTip_box">
                    <p class="toolTip_text f16">确定取消该订单吗？</p>
                    <a class="msg_cancel_btn">再等等</a><a class="msg_sure_btn">确定</a>
                </div>
            </div>
            <!--订单取消确定提示提示弹窗结束-->
            <!--订单取消下单成功提示弹窗开始-->
            <div class="msg-succ">
                <p class="f16">订单已取消</p>
            </div>
            <!--订单取消下单成功提示弹窗结束-->
        </div>
        <input type="hidden" id="userId" value="${userVo.bId }"/>
        <script type="text/javascript" src="<c:url value="/static/wx/js/lib/jquery-3.3.1.min.js"/>" ></script>
        <script>
            //首部导航切换
            $(".ul-tab-btn").on("click","li",function(){
                //选项卡按钮样式切换
                 $(this).addClass("on").siblings("li").removeClass("on");
            })
            function ifCancel(id) {
                $(".mask").show();
              //取消按钮
                $(".msg_sure_btn").on("click",function(){
                    $(".mask").hide();
                    var f = arguments.callee, self = this;
                    $(self).unbind('click', f);  
                    $.ajax({
                        type: "post",
                        url: "<c:url value="/wx/updateOrder.do"/>",
                        data: {
                            bId : id,
                            status : 3
                        },
                        cache: false, 
                        async:false, 
                        dataType: "json",
                        success: function(data){
                            if (data.msg != null) {
                                $(".msg-succ").show();
                                setTimeout(hideTips, 3000);
                                serchOrderList('');
                            }
                            $(self).click(f);
                        }
                    });
                })
            }
            
            $(".msg_cancel_btn").on("click",function(){
                $(".mask").hide();
            })
            
            function hideTips(){
                $(".msg-succ").hide();
            }
            
            $(document).ready(function(){
                serchOrderList('');
            })
            
            var userId = $("#userId").val();
            function serchOrderList(status){
                $.ajax({
                    type: "post",
                    url: "<c:url value="/wx/serchReceiptOrderList.do"/>",
                    data: {
                        userId : userId,
                        status : status,
                        page : 1,
                        size : 99
                    },
                    cache: false, 
                    async:false, 
                    dataType: "json",
                    success: function(data){
                        var result = "";
                        var result2 = "";
                        if (data.wOrderVo.length>0) {
                            for (var i = 0 ; i<data.wOrderVo.length;i++) {
                                result += '<ul class="ul-tab-content common" >';
                                if (data.wOrderVo[i].pickTime != null) {
                                	result += '<li>预约 '+data.wOrderVo[i].pickTime;
                                }else {
                                	result += '<li>扫码订单';
                                }
                                
                                switch (data.wOrderVo[i].status) {
                                    case 1:
                                        result += '<span class="c41afa5">已受理</span>';
                                        break;
                                    case 2:
                                        result += '<span>已完成</span>';
                                        break;
                                    case 3:
                                        result += '<span>已取消</span>';
                                        break;
                                    case 4:
                                        result += '<span class="cff6633">无人接单</span>';
                                        break;
                                }
                                    
                                result += '</li>';
                                if (data.wOrderVo[i].status == '2') {
                                	result+='<li class="goValuation fr"><a href=\'<c:url value='/wx/toEvaluate.do'/>?sendUserId='+userId+'&userId='+data.wOrderVo[i].receiptId+'&orderId='+data.wOrderVo[i].orderNumber+'\'>评价</a></li>';
                                	if (data.wOrderVo[i].orderPriceVos.length>0) {
                                		for (var j = 0 ; j<data.wOrderVo[i].orderPriceVos.length;j++) {
                                            result += '<li>'+data.wOrderVo[i].orderPriceVos[j].priceName + "  " ;
                                            result += data.wOrderVo[i].orderPriceVos[j].actualWeight + "kg" + "  "  + data.wOrderVo[i].orderPriceVos[j].price + "元/kg";
                                            result += '</li>';
                                        }
                                	}
                                }else {
                                	result += '<li>'+"回收类别：  ";
                                	if (data.wOrderVo[i].orderCategoryVos.length>0) {
                                		for (var k = 0 ; k<data.wOrderVo[i].orderCategoryVos.length;k++) {
                                            result += data.wOrderVo[i].orderCategoryVos[k].name + "  ";
                                        }
                                         result += '</li>';
                                        
                                        result += '<li>'+"货量范围：  ";
                                        result += data.wOrderVo[i].orderCategoryVos[0].weight;
                                        result += '</li>';
                                	}
                                }
                                
                                result += '<li>下单时间：  '+data.wOrderVo[i].createTime.substring(5,16)+'';
                                if (data.wOrderVo[i].countPrice != '0') {
                                	result += '<span class="cff6633 fr">总计:'+data.wOrderVo[i].countPrice.toFixed(2)+'元</span>';
                                }
                                result += '</li>';
                                switch (data.wOrderVo[i].status) {
                                case 1:
                                    result += '<li class="clearfix">';
                                    result += '<a class="tel_btn fr" href=tel:'+data.wOrderVo[i].receiptTelephone+'>致电回收员</a>';
                                    result += "<a class='cancel_btn fr' onclick=\"ifCancel('"+data.wOrderVo[i].bId+"')\">取消</a>";
                                    result += '</li>';
                                    break;
                                }
                                result += '</ul>';
                            }
                            
                            $("#order_list").show();
                            $("#no_list").hide();
                            $("#order_list").html(result);
                        }else {
                            result += "";//toWxClientHome
                            result += "<img src=\"<c:url value="/static/wx/img/no_data.png"/>\" />";
                            result += '<p>您还没相关订单哦</p>';
                            result += "<a class=\"order_btn\" href=\"<c:url value="/wx/toOrder.do"/>?id="+userId+"\">开始预约回收</a>";
                            $("#order_list").hide();
                            $("#no_list").show();
                            $("#no_list").html(result);
                        }
                    }
                })
            }
        </script>
    </body>
</html>
